#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   sorted_set.py
@Time    :   2024-07-09 13:02:55
@Author  :   chakcy 
@Email   :   947105045@qq.com
@description   :   redis sorted set 操作
'''

from redis.asyncio import Redis

class SortedSet:
    def __init__(self, redis: Redis):
        """初始化 Redis 连接"""
        self.redis = redis
    async def get_value(self, key: str, member: str): 
        """获取指定成员的分数"""
        return await self.redis.zscore(key, member) 
    async def set_value(self, key: str, member: str, score: float): 
        """添加值到有序集合"""
        return await self.redis.zadd(key, {member: score}) 
    async def delete_value(self, key: str, member: str): 
        """删除指定值"""
        return await self.redis.zrem(key, member) 
    async def get_all_values(self, key: str): 
        """获取指定键的所有成员和分数"""
        return await self.redis.zrange(key, 0, -1, withscores=True) 